<template>
  <div id="app" class="app-background">
    <div class="center-container">
      <el-card class="login-card">
        <div slot="header" class="login-header">
          <h3 class="custom-font animated-text">中移用户登录</h3>
        </div>
        <el-form ref="loginForm" class="login-form" :model="loginForm" label-width="0">
          <el-form-item prop="username">
            <el-input v-model="loginForm.username" placeholder="请输入手机号" clearable></el-input>
          </el-form-item>
          <el-form-item prop="password">
            <el-input
              type="password"
              v-model="loginForm.pwd"
              placeholder="请输入密码"
              clearable
              show-password
            ></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="login">登录</el-button>
          </el-form-item>
        </el-form>
      </el-card>
    </div>
  </div>
</template>
  
  <script>
export default {
  data() {
    return {
      loginForm: {
        username: "13862700450",
        pwd: "123456"
      }
    };
  },
  methods: {
    login() {
      let params = new URLSearchParams();
      params.append("username", this.loginForm.username);
      params.append("pwd", this.loginForm.pwd);

      this.$axios
        .post("/api/zgyd-user/login", params)
        .then(res => {
          if (res.data.code === 200) {
            localStorage.setItem("token", res.data.data);
            localStorage.setItem('username', this.loginForm.username);  
            this.$router.push({ path: "/home" });
          }
          if(res.data.code === 500) {
            this.$message.error("账号密码错误", error);
          }
        })
        .catch(error => {
          this.$message.error("登录失败", error);
        });
    }
  }
};
</script>
  
<style scoped>
body,html {
  margin: 0;
  padding: 0;
  height: 100%;
}

.app-background {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: url("../assets/logo.png") center/cover no-repeat;
}

.center-container {
  width: 100%;
  max-width: 400px;
}

.login-card {
  border-radius: 10px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
  text-align: center;
}

.login-form {
  padding: 10px;
}

.form-footer {
  margin-top: 20px;
}

.form-footer span {
  color: #666;
}

.form-footer a {
  color: #409eff;
  text-decoration: none;
}

.form-footer a:hover {
  text-decoration: underline;
}



.custom-font {
  font-family: "Dancing Script", cursive;
  /* 可以根据需要调整字体大小、颜色等样式 */
  font-size: 28px;
  color: white;
}

@keyframes bounce {
  0%,
  20%,
  50%,
  80%,
  100% {
    transform: translateY(0);
  }

  40% {
    transform: translateY(-10px);
  }

  60% {
    transform: translateY(-5px);
  }
}

.animated-text {
  animation: bounce 1s infinite;
}

.login-card {
  border-radius: 10px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
  text-align: center;
  background: url("../assets/back.png") center/cover no-repeat;
}
</style>
  